
//
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main()
{
	long long int n, k, d=0, yu=0;
	scanf("%lld%lld", &n, &k);
	while(1) {
		d += n;
		n += yu;
		if (n < k)
			break;
		yu = n % k;
		n = n / k;
	}
	printf("%lld", d);
	return 0;
}